package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.HhBrand;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IHhBrandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品品牌Controller
 * 
 * @author ruoyi
 * @date 2021-06-15
 */
@RestController
@RequestMapping("/system/brand")
public class HhBrandController extends BaseController
{
    @Autowired
    private IHhBrandService hhBrandService;

    /**
     * 查询商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(HhBrand hhBrand)
    {
        startPage();
        List<HhBrand> list = hhBrandService.selectHhBrandList(hhBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:export')")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HhBrand hhBrand)
    {
        List<HhBrand> list = hhBrandService.selectHhBrandList(hhBrand);
        ExcelUtil<HhBrand> util = new ExcelUtil<HhBrand>(HhBrand.class);
        return util.exportExcel(list, "商品品牌数据");
    }

    /**
     * 获取商品品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:brand:query')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return AjaxResult.success(hhBrandService.selectHhBrandById(brandId));
    }

    /**
     * 新增商品品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:add')")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HhBrand hhBrand)
    {
        int flag = hhBrandService.insertHhBrand(hhBrand);
        if (flag<=0){
            return AjaxResult.error("操作失败，可能不存在相应类型");
        }
        return toAjax(flag);
    }

    /**
     * 修改商品品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:edit')")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HhBrand hhBrand)
    {
        int flag = hhBrandService.updateHhBrand(hhBrand);
        if (flag<=0){
            return AjaxResult.error("操作失败，可能不存在相应类型");
        }
        return toAjax(flag);
    }

    /**
     * 删除商品品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:remove')")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Long[] brandIds)
    {
        return toAjax(hhBrandService.deleteHhBrandByIds(brandIds));
    }
}
